package com.cy.system.aspect;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import com.cy.system.annotation.DataSource;
import com.cy.system.config.DataSourceContextHolder;

@Aspect
@Component
@Order(0)
public class DataSourceAspect {
	
	@Around("within(com.cy..*) && @annotation(dataSource)")
	public Object doAroundMethod(ProceedingJoinPoint pjd,DataSource dataSource) {
		DataSourceContextHolder.setDbType(dataSource.dataSourceType());
		System.out.println(dataSource.dataSourceType());
		//###################上面代码为方法执行前#####################
		Object result = "";
        try {
			result  = pjd.proceed();
			
		} catch (Throwable e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}//执行方法，获取返回参数
        //###################下面代码为方法执行后#####################
        DataSourceContextHolder.clearDbType();
        return result;
	}
}
